﻿using System.Collections;
using System.Collections.Generic;
using Unity.Entities;
using Unity.Mathematics;
using Unity.Transforms;
using UnityEngine;

[UpdateAfter(typeof(PlayerInputSystem))]
public class MovementSystem : ComponentSystem
{
    protected override void OnUpdate()
    {
        Entities.WithAll<CharacterTag>().ForEach(
            (ref Translation translation, ref Rotation rotation, ref PlayerInputData inputData, ref MovementData movementData) =>
            {
                float3 direction = new float3(inputData.MoveX, inputData.MoveY, 0);

                var toPosition = translation.Value + movementData.MoveSpeed * Time.DeltaTime * direction;
                if(toPosition.x > 9f)
                {
                    toPosition.x = 9f;
                }
                if(toPosition.x < - 9f)
                {
                    toPosition.x = -9f;
                }
                if(toPosition.y > 5f)
                {
                    toPosition.y = 5f;
                }
                if(toPosition.y < -3.6f)
                {
                    toPosition.y = -3.6f;
                }

                translation.Value = toPosition;
                //math.d
                //rotation.Value = quaternion.Euler(new float3())
                //var angle = 
            });
    }
}
